package com.uzai.console.web.alarm;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.common.enums.SysMsgTypeEnum;
import com.uzai.console.dto.alarm.alarmmsg.AlarmMsgQuery;
import com.uzai.console.dto.uzaichat.kefuuser.KefuUserQuery;
import com.uzai.console.entity.KefuUser;
import com.uzai.console.entity.Merchant;
import com.uzai.console.entity.es.EsAlarmMsg;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.mapper.KefuUserMapper;
import com.uzai.console.mapper.MerchantMapper;
import com.uzai.console.service.alarm.AlarmMsgService;
import com.uzai.console.service.device.DeviceService;
import com.uzai.console.vo.alarm.alarmmsg.AlarmMsgVo;
import com.uzai.console.vo.base.SelectKeyVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 报警记录
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "报警记录",tags = "云监控|报警记录")
@ApiSort(19)
@RestController
public class AlarmMsgController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(AlarmMsgController.class);

    @Autowired
    private AlarmMsgService alarmMsgService;
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private MerchantMapper merchantMapper;
    @Autowired
    private KefuUserMapper kefuUserMapper;

    @ApiOperation(value = "查询报警记录列表", notes = "查询报警记录列表", response = AlarmMsgVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/alarmMsg/findAlarmMsgList")
    public Object findAlarmMsgList(@RequestBody AlarmMsgQuery alarmMsgQuery){
        return alarmMsgService.findAlarmMsgList(alarmMsgQuery);
    }

    @ApiOperation(value = "查询事件监控消息类型下拉列表", notes = "查询事件监控消息类型下拉列表", response = SelectKeyVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/alarmMsg/findMsgTypeList")
    public Object findMsgTypeList(){
        List<SelectKeyVo> selectKeyVoList = new ArrayList<>();
        //先封装主账号
        SysMsgTypeEnum[] sysMsgTypeEnums = SysMsgTypeEnum.values();
        if(sysMsgTypeEnums != null){
            for (SysMsgTypeEnum sysMsgTypeEnum : sysMsgTypeEnums){
                if(sysMsgTypeEnum.getValue().intValue() < 500){
                    if(sysMsgTypeEnum.getValue().intValue() != SysMsgTypeEnum.DY_TOKEN_EXPIRED.getValue()){ //去除抖客联盟到期报警
                        SelectKeyVo selectKeyVo = new SelectKeyVo();
                        selectKeyVo.setKey(String.valueOf(sysMsgTypeEnum.getValue()));
                        selectKeyVo.setValue(sysMsgTypeEnum.getDesc());
                        selectKeyVoList.add(selectKeyVo);
                    }
                }
            }
        }
        return selectKeyVoList;
    }


    @ApiOperation(value = "查询风险监控消息类型下拉列表", notes = "查询风险监控消息类型下拉列表", response = SelectKeyVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/alarmMsg/findRiskMsgTypeList")
    public Object findRiskMsgTypeList(){
        List<SelectKeyVo> selectKeyVoList = new ArrayList<>();
        //先封装主账号
        SysMsgTypeEnum[] sysMsgTypeEnums = SysMsgTypeEnum.values();
        if(sysMsgTypeEnums != null){
            for (SysMsgTypeEnum sysMsgTypeEnum : sysMsgTypeEnums){
                if(sysMsgTypeEnum.getValue().intValue() >= 500){
                    SelectKeyVo selectKeyVo = new SelectKeyVo();
                    selectKeyVo.setKey(String.valueOf(sysMsgTypeEnum.getValue()));
                    selectKeyVo.setValue(sysMsgTypeEnum.getDesc());
                    selectKeyVoList.add(selectKeyVo);
                }
            }
        }
        return selectKeyVoList;
    }

}
